package org.example.login2;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import java.io.IOException;
import java.util.List;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

@WebServlet("/saveStudent")
public class SaveStudentServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Student> studentList = InMemoryStudentDatabase.getStudentList();

        for (Student student : studentList) {
            int regularScore = Integer.parseInt(req.getParameter("regularScore_" + student.getId()));
            int finalScore = Integer.parseInt(req.getParameter("finalScore_" + student.getId()));
            student.setRegularScore(regularScore);
            student.setFinalScore(finalScore);
        }

        resp.sendRedirect("studentList");
    }
}
